/*  1:   */ package cn.com.dashihui.pay.SQ.test;
/*  2:   */ 
/*  3:   */ import java.util.ArrayList;
/*  4:   */ import java.util.Collections;
import java.util.HashMap;
/*  5:   */ import java.util.List;
/*  6:   */ import java.util.Map;
/*  7:   */ import org.apache.commons.lang.StringUtils;

import net.sf.json.JSONObject;
/*  8:   */ 
/*  9:   */ public class EncryUtils
/* 10:   */ {
/* 11:   */   public static StringBuilder createLinkString(Map<String, String> params)
/* 12:   */   {
/* 13:13 */     List<String> keys = new ArrayList(params.keySet());
/* 14:14 */     Collections.sort(keys);
/* 15:   */     
/* 16:16 */     StringBuilder prestr = new StringBuilder();
/* 17:17 */     String key = "";
/* 18:18 */     String value = "";
/* 19:20 */     for (int i = 0; i < keys.size(); i++)
/* 20:   */     {
/* 21:21 */       key = (String)keys.get(i);
/* 22:22 */       value = (String)params.get(key);
/* 23:23 */       if ((!"".equals(value)) && (value != null) && (!key.equalsIgnoreCase("SIGN_STR"))) {
/* 24:26 */         prestr.append(value).append("&");
/* 25:   */       }
/* 26:   */     }
/* 27:28 */     return prestr.deleteCharAt(prestr.length() - 1);
/* 28:   */   }
/* 29:   */   
/* 30:   */   public static String sign(Map<String, String> params, String merPrivateKey)
/* 31:   */   {
/* 32:32 */     String sign = "";
/* 33:33 */     if (StringUtils.isNotEmpty(merPrivateKey)) {
/* 34:34 */       sign = RSA.sign(createLinkString(params).toString(), merPrivateKey);
/* 35:   */     }
/* 36:37 */     return sign;
/* 37:   */   }
/* 38:   */   
/* 39:   */   public static boolean checkSign(Map<String, String> params, String dowmerPublicKey)
/* 40:   */     throws Exception
/* 41:   */   {
/* 42:41 */     String sign = StringUtils.trimToEmpty((String)params.get("SIGN_STR"));
/* 43:   */     
/* 44:43 */     return RSA.checkSign(createLinkString(params).toString(), sign, dowmerPublicKey);
/* 45:   */   }
/* 45:   */   public static  Map<String,Object>  toMap(JSONObject json) {
				Map<String,Object> map = new HashMap<String,Object>();
			    map.put("result", json.get("result"));
			    map.put("msg", json.get("msg"));
			    map.put("data", JSONObject.fromObject(json.get("data")));
				return map;
			  }
/* 46:   */ }

